package lanqiao;

import java.util.Arrays;
import java.util.Scanner;

public class F数组翻转 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] nums = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        System.out.println(getResult(n,nums));
    }

    public static int getResult(int n,int[] nums) {
        int sum = 0;
        int max = 0;
        for (int i=0;i<n;i++) {
            for (int j=i+1;j<n;j++) {
                int[] newNums = reverse(nums,i,j);
                int target = newNums[0];
                sum=0;
                for (int k=0;k<n;k++) {
                     if (target == newNums[k]) {
                         sum+=target;
                         if (k==n-1) {
                             max = Math.max(sum,max);
                         }
                     } else if(target!=newNums[k]) {
                         max = Math.max(max,sum);
                         target = newNums[k];
                         sum = target;
                     }
                }
            }
        }
        return max;
    }

    public static int[] reverse(int[] nums,int left,int right) {
        int[] newNums = Arrays.copyOf(nums,nums.length);
           while(left<right) {
               int temp = newNums[left];
               newNums[left] = newNums[right];
               newNums[right] = temp;
               left++;
               right--;
           }
           return newNums;
    }
}
